package com.zone.service.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zone.common.log.annotation.Log;
import com.zone.common.log.enums.BusinessType;
import com.zone.common.security.annotation.RequiresPermissions;
import com.zone.service.domain.GunInoutRecord;
import com.zone.service.domain.GunSummary;
import com.zone.service.service.IGunInoutRecordService;
import com.zone.common.core.web.controller.BaseController;
import com.zone.common.core.web.domain.AjaxResult;
import com.zone.common.core.utils.poi.ExcelUtil;
import com.zone.common.core.web.page.TableDataInfo;

/**
 * 枪弹出入流水Controller
 * 
 * @author ningbo
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/record")
public class GunInoutRecordController extends BaseController
{
    @Autowired
    private IGunInoutRecordService gunInoutRecordService;

    /**
     * 查询枪弹出入流水列表
     */
    @RequiresPermissions("service:record:list")
    @GetMapping("/list")
    public TableDataInfo list(GunInoutRecord gunInoutRecord)
    {
        startPage();
        List<GunInoutRecord> list = gunInoutRecordService.selectGunInoutRecordList(gunInoutRecord);
        return getDataTable(list);
    }

    @RequiresPermissions("service:record:summary")
    @GetMapping("/summary/list")
    public TableDataInfo summary(GunSummary query)
    {
        startPage();
        List<GunSummary> list = gunInoutRecordService.selectSummaryList(query);
        return getDataTable(list);
    }

    /**
     * 导出枪弹出入流水列表
     */
    @RequiresPermissions("service:record:export")
    @Log(title = "枪弹出入流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GunInoutRecord gunInoutRecord)
    {
        List<GunInoutRecord> list = gunInoutRecordService.selectGunInoutRecordList(gunInoutRecord);
        ExcelUtil<GunInoutRecord> util = new ExcelUtil<GunInoutRecord>(GunInoutRecord.class);
        util.exportExcel(response, list, "枪弹出入流水数据");
    }

    /**
     * 获取枪弹出入流水详细信息
     */
    @RequiresPermissions("service:record:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gunInoutRecordService.selectGunInoutRecordById(id));
    }

    /**
     * 新增枪弹出入流水
     */
    @RequiresPermissions("service:record:add")
    @Log(title = "枪弹出入流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GunInoutRecord gunInoutRecord)
    {
        return toAjax(gunInoutRecordService.insertGunInoutRecord(gunInoutRecord));
    }

    /**
     * 修改枪弹出入流水
     */
    @RequiresPermissions("service:record:edit")
    @Log(title = "枪弹出入流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GunInoutRecord gunInoutRecord)
    {
        return toAjax(gunInoutRecordService.updateGunInoutRecord(gunInoutRecord));
    }

    /**
     * 删除枪弹出入流水
     */
    @RequiresPermissions("service:record:remove")
    @Log(title = "枪弹出入流水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gunInoutRecordService.deleteGunInoutRecordByIds(ids));
    }
}
